interface IShape {
    double getArea();
    double getPeri();
//    public void display();
}

class Rectangle implements IShape {
    private double length, width;
    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
    @Override
    public double getArea() {
        return this.length * this.width;
    }
    @Override
    public double getPeri() {
        return (length + width) * 2;
    }
}

class Square implements IShape {
    private double width;
    public Square(double width) {
        this.width = width;
    }
    @Override
    public double getArea() {
        return width * width;
    }
    @Override
    public double getPeri() {
        return width * 4;
    }

    public void display() {

    }
}

public class Test {
    public static void main(String[] args) {
        // 父类型的引用可以指向任何子类型的对象
        //1.求长方形的面积和周长
        IShape shape = new Rectangle(5.0, 6.0);
        double area = shape.getArea();//求长方形的面积，但只能在运行阶段确定
        double peri = shape.getPeri();
        //2.求正反面的面积和周长
        shape = new Square(5.0);
        area = shape.getArea();
        peri = shape.getPeri();
        // 下行代码在编译阶段通不过
//        shape.display();
    }
}
